using System.Collections.Generic;
using Entitas;
using UnityEngine;

public sealed class SlowMotionSystem : ReactiveSystem {

    public SlowMotionSystem(Contexts contexts) : base(contexts.input) {

    }

    protected override Collector GetTrigger(Context context) {
        return context.CreateCollector(InputMatcher.SlowMotion, GroupEvent.AddedOrRemoved);
    }

    protected override bool Filter(Entity entity) {

        return true;
    }

    protected override void Execute(List<Entity> entities) {
        Time.timeScale = entities.SingleEntity().isSlowMotion
            ? 0.3f
            : 1f;
    }
}
